package cn.com.dycc.util;

import java.io.File;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import cn.com.dycc.common.attach.dao.AttachDao;
import cn.com.dycc.common.attach.entity.Attach;

/**
 * 附件工具类
 * @author gaofan
 *
 */
public class AttachUtil {
	
	//附件常量
	public final static String member_apply_attach_type = "1"; //党员申请入党信息表附件 
	
	public final static String party_member_attach_type = "2"; //党员信息表附件
	
	public final static String party_information_attach_type = "3"; //党建资讯信息表附件
	  
	public final static String party_information_lst_attach_type = "301";  // 党建资讯信息表缩略图
	
	public final static String special_activity_attach_type = "4"; //专题活动的信息表附件
	
	public final static String special_activity_lst_attach_type = "401";  //专题活动信息表缩略图
	
	public final static String activity_result_attach_type = "5";  //专题活动的成果汇报的附件
	
	public final static String party_education_attach_type = "6";	//党员教育学习的信息表附件
	
	public final static String party_education_lst_attach_type = "601"; //党员教育学习信息表缩略图
	
	public final static String education_result_attach_type = "7";  //党员教育学习的成果汇报附件
	
	public final static String education_result_dept_attach_type = "8"; // 党员教育学习的单位成果汇报附件
	
	public final static String order_main_attach_type = "9"; // 任务直通车模块附件
	 
	
	/**
	 * 保存附件信息,并将临时附件移到正式目录下
	 * @param jsonStr 数组json字符串
	 * @param message_no 对应消息/文档ID//业务ID等
	 * @param attach_type 文档类型
	 * @param org_id 组织id
	 * @param opt_user_id 创建人id
	 * @param model 附件所属模块
	 * @param attachDao 附件数据层
	 * @param request 请求对象
	 */
	public static void saveAttachInfo(String jsonStr,String message_no,String attach_type,String org_id,String opt_user_id,String model,AttachDao attachDao,HttpServletRequest request){
		
		List<Attach> listAttach=StringUtil.getListAttach(jsonStr, message_no, attach_type, org_id, opt_user_id);		
		List<Attach> newListAttach=FileUtil.moveFile(listAttach,model);
		int m=0;
		if(newListAttach!=null){
			for(Attach attach:newListAttach){
				int n=attachDao.insertAttach(attach);
				m+=n;
			}
			
		}
		
	}
	
	public static void removeFile(String path){
		File old_file_Path = new File(path);
		if(old_file_Path.exists()){
			old_file_Path.delete();
		}
	}
	
	

}
